package thread;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-30
 * Time: 21:20
 */
//线程池简化创建方法
public class Demo34 {
    public static void main(String[] args) {
        //ExecutorService threadPool = Executors.newFixedThreadPool(5);//核心线程数和最大线程数一样
        ExecutorService threadPool = Executors.newCachedThreadPool();//最大线程是一个很大的数字(可以无限增加)

        for (int i = 0; i < 1000; i++) {
            int id = i;
            threadPool.submit(() -> {
                System.out.println("hello " + id + Thread.currentThread().getName());
            });
        }

        threadPool.shutdown();
    }
}
